#include "Tank.h"
#include <QImage>
#include <QPoint>

Tank::Tank(QObject *parent) : QObject(parent)
{
    tank=QImage(":/map_image/element/tank.png");
    pos_x=tank.width();
    pos_y=tank.height();
    moveStep=20;
    QuickmoveStep=10;
    mydir=xup;
}

void Tank::DrawTank(QPainter* p,direction d)
{
    p->translate(QPoint(pos_x,pos_y));
    p->rotate(qreal(90)*d);
    if(d == xup)
    {
        p->drawImage(0,0,tank);
    }
    else if(d == xright)
    {
        p->drawImage(0,-tank.height(),tank);
    }
    else if(d == xdown)
    {
        p->drawImage(-tank.width(),-tank.height(),tank);
    }
    else if(d == xleft)
    {
        p->drawImage(-tank.width(),0,tank);
    }
}

void Tank::move(int dx,int dy)
{
    pos_x=dx+pos_x;
    pos_y=dy+pos_y;
}
